package dry.example.gui;

import javax.swing.*;
import java.awt.*;

public class BorderLayoutDemo {

    public static void main(String[] args) {

        // 创建主窗口
        JFrame frame = new JFrame("BorderLayout 示例");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 400);

        // 设置布局为 BorderLayout
        frame.setLayout(new BorderLayout());

        // 创建不同区域的组件
        JButton northButton = new JButton("北方");
        JButton southButton = new JButton("南方");
        JButton eastButton = new JButton("东方");
        JButton westButton = new JButton("西方");
        JTextArea centerTextArea = new JTextArea("中央区域", 10, 20);

        // 将组件添加到对应的 BorderLayout 区域
        frame.add(northButton, BorderLayout.NORTH);
        frame.add(southButton, BorderLayout.SOUTH);
        frame.add(eastButton, BorderLayout.EAST);
        frame.add(westButton, BorderLayout.WEST);
        frame.add(new JScrollPane(centerTextArea), BorderLayout.CENTER); // 使用滚动条包裹文本区

        // 显示窗口
        frame.setVisible(true);
    }

}
